using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Lifter.Gui.Monitor.Contain
{
    public abstract class BaseContainer : GroupBox, IGradientContainer, IFontColor, IGradientBackgroundColor, IGradientBorderColor
    {
        private const int IDEFAULT_BORDERWIDTH = 6;
        private Size ODEFAULT_SIZEBORDERPIXELINDET = new Size(16, 16);
        private static Color ODEFAULT_GRADIENTTOPCOLOR = Color.FromArgb(225, 225, 183);
        private static Color ODEFAULT_GRADIENTBOTTOMCOLOR = Color.FromArgb(167, 168, 127);
        private static Color ODEFAULT_HEADINGTEXTCOLOR = Color.FromArgb(57, 66, 1);
        private static Color ODEFAULT_INTERIORTOPCOLOR = Color.FromArgb(245, 243, 219);
        private static Color ODEFAULT_INTERIORBOTTOMCOLOR = Color.FromArgb(214, 209, 153);
        private static Color ODEFAULT_SHADOWCOLOR = Color.FromArgb(142, 143, 116);
        protected float[] IARR_RELATIVEINTENSITIES = new float[]
        {
            0f,
            0.32f,
            1f
        };
        protected float[] IARR_RELATIVEPOSITIONS = new float[]
        {
            0f,
            0.44f,
            1f
        };
        private int miBorderWidth = 6;
        private Color moGradientTopColor = BaseContainer.ODEFAULT_GRADIENTTOPCOLOR;
        private Color moGradientBottomColor = BaseContainer.ODEFAULT_GRADIENTBOTTOMCOLOR;
        private Color moHeadingTextColor = BaseContainer.ODEFAULT_HEADINGTEXTCOLOR;
        private Color moInteriorTopColor = BaseContainer.ODEFAULT_INTERIORTOPCOLOR;
        private Color moInteriorBottomColor = BaseContainer.ODEFAULT_INTERIORBOTTOMCOLOR;
        private Color moShadowColor = BaseContainer.ODEFAULT_SHADOWCOLOR;
        protected Size mosizeBorderPixelIndent;
        protected SizeF moTextSize;
        protected Rectangle BorderRectangle
        {
            get
            {
                Rectangle clientRectangle = base.ClientRectangle;
                return new Rectangle(1, 1, clientRectangle.Width - 3, clientRectangle.Height - 3);
            }
        }
        public Color ShadowColor
        {
            get
            {
                return this.moShadowColor;
            }
            set
            {
                this.moShadowColor = value;
                base.Invalidate();
            }
        }
        public Color FontColor
        {
            get
            {
                return this.moHeadingTextColor;
            }
            set
            {
                this.moHeadingTextColor = value;
            }
        }
        Color IGradientBorderColor.BorderTopColor
        {
            get
            {
                return this.moGradientTopColor;
            }
            set
            {
                this.moGradientTopColor = value;
            }
        }
        Color IGradientBorderColor.BorderBottomColor
        {
            get
            {
                return this.moGradientBottomColor;
            }
            set
            {
                this.moGradientBottomColor = value;
            }
        }
        Color IGradientBackgroundColor.BackgroundTopColor
        {
            get
            {
                return this.moInteriorTopColor;
            }
            set
            {
                this.moInteriorTopColor = value;
            }
        }
        Color IGradientBackgroundColor.BackgroundBottomColor
        {
            get
            {
                return this.moInteriorBottomColor;
            }
            set
            {
                this.moInteriorBottomColor = value;
            }
        }
        public abstract EnmColorScheme ColorScheme
        {
            get;
            set;
        }
        public int BorderWidth
        {
            get
            {
                return this.miBorderWidth;
            }
            set
            {
                this.miBorderWidth = value;
                base.Invalidate();
            }
        }
        protected virtual Brush InteriorRegionPathBrush
        {
            get
            {
                return new LinearGradientBrush(base.ClientRectangle, this.moGradientTopColor, this.moGradientBottomColor, LinearGradientMode.Vertical)
                {
                    Blend = new Blend
                    {
                        Factors = this.IARR_RELATIVEINTENSITIES,
                        Positions = this.IARR_RELATIVEPOSITIONS
                    }
                };
            }
        }
        protected virtual GraphicsPath ExteriorRegionPath
        {
            get
            {
                Rectangle aoRectangle = new Rectangle(this.BorderRectangle.X, this.BorderRectangle.Y, this.BorderRectangle.Width + 3, this.BorderRectangle.Height + 3);
                Size aoSize = new Size(this.mosizeBorderPixelIndent.Width + 2, this.mosizeBorderPixelIndent.Height + 2);
                return this.GetRoundedRectanglarPath(aoRectangle, aoSize);
            }
        }
        protected virtual GraphicsPath InteriorRegionPath
        {
            get
            {
                Rectangle aoRectangle = new Rectangle(this.BorderRectangle.X + 1, this.BorderRectangle.Y + 1, this.BorderRectangle.Width - 2, this.BorderRectangle.Height - 2);
                Size aoSize = new Size(this.mosizeBorderPixelIndent.Width - 2, this.mosizeBorderPixelIndent.Height - 2);
                return this.GetRoundedRectanglarPath(aoRectangle, aoSize);
            }
        }
        public BaseContainer()
        {
            base.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
            this.mosizeBorderPixelIndent = this.ODEFAULT_SIZEBORDERPIXELINDET;
        }
        protected virtual void DrawBorder(Graphics aoGraphics, Rectangle aoRectangle)
        {
            Size size = new Size(this.mosizeBorderPixelIndent.Width, this.mosizeBorderPixelIndent.Height);
            Rectangle rectangle = new Rectangle(aoRectangle.X, aoRectangle.Y, aoRectangle.Width, aoRectangle.Height);
            SizeF sizeF = aoGraphics.MeasureString(this.Text, this.Font);
            aoGraphics.SmoothingMode = SmoothingMode.AntiAlias;
            for (int i = 0; i < 3; i++)
            {
                Pen pen = new Pen(Color.FromArgb((2 - i + 1) * 64, this.moShadowColor));
                aoGraphics.DrawArc(pen, rectangle.Right - size.Width, rectangle.Top + 2, size.Width, size.Height, 270, 90);
                aoGraphics.DrawLine(pen, (float)rectangle.Right, (float)rectangle.Top + (float)(size.Height / 2), (float)rectangle.Right, (float)rectangle.Bottom - (float)(size.Height / 2));
                aoGraphics.DrawArc(pen, rectangle.Right - size.Width, rectangle.Bottom - size.Height, size.Width, size.Height, 0, 90);
                aoGraphics.DrawLine(pen, (float)rectangle.Right - (float)(size.Width / 2), (float)rectangle.Bottom, (float)rectangle.Left + (float)(size.Width / 2), (float)rectangle.Bottom);
                pen = new Pen(Color.FromArgb((2 - i) * 127, this.moShadowColor));
                aoGraphics.DrawArc(pen, rectangle.Left + 2, rectangle.Bottom - size.Height, size.Width, size.Height, 90, 90);
                rectangle.X++;
                rectangle.Y++;
                rectangle.Width -= 2;
                rectangle.Height -= 2;
                size.Height -= 2;
                size.Width -= 2;
            }
        }
        protected virtual void DrawInterior(Graphics aoGraphics)
        {
            aoGraphics.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rect = new Rectangle(this.BorderRectangle.X + this.miBorderWidth + 1, this.BorderRectangle.Y + 12 + this.miBorderWidth, this.BorderRectangle.Width - this.miBorderWidth * 2, this.BorderRectangle.Height - (12 + this.miBorderWidth * 2));
            for (int i = 1; i >= 0; i--)
            {
                SolidBrush brush = new SolidBrush(Color.FromArgb(127 * (2 - i), this.moShadowColor));
                Pen pen = new Pen(brush);
                aoGraphics.DrawLine(pen, rect.X, rect.Y, rect.X, rect.Bottom);
                aoGraphics.DrawLine(pen, rect.X, rect.Y, rect.Right, rect.Y);
                rect.X++;
                rect.Y++;
                rect.Width -= 2;
                rect.Height -= 2;
            }
            if (rect.Width <= 0)
            {
                rect.Width = 1;
            }
            if (rect.Height <= 0)
            {
                rect.Height = 1;
            }
            aoGraphics.FillRectangle(new LinearGradientBrush(rect, this.moInteriorTopColor, this.moInteriorBottomColor, LinearGradientMode.Vertical)
            {
                Blend = new Blend
                {
                    Factors = this.IARR_RELATIVEINTENSITIES,
                    Positions = this.IARR_RELATIVEPOSITIONS
                }
            }, rect);
        }
        private GraphicsPath GetRoundedRectanglarPath(Rectangle aoRectangle, Size aoSize)
        {
            GraphicsPath graphicsPath = new GraphicsPath();
            graphicsPath.AddLine((float)aoRectangle.Left + (float)(aoSize.Height / 2), (float)aoRectangle.Top, (float)aoRectangle.Right - (float)(aoSize.Height / 2), (float)aoRectangle.Top);
            graphicsPath.AddArc(aoRectangle.Right - aoSize.Width, aoRectangle.Top, aoSize.Width, aoSize.Height, 270f, 90f);
            graphicsPath.AddLine((float)aoRectangle.Right, (float)(aoRectangle.Top + aoSize.Height), (float)aoRectangle.Right, (float)aoRectangle.Bottom - (float)(aoSize.Height / 2));
            graphicsPath.AddArc(aoRectangle.Right - aoSize.Width, aoRectangle.Bottom - aoSize.Height, aoSize.Width, aoSize.Height, 0f, 90f);
            graphicsPath.AddLine((float)aoRectangle.Right - (float)(aoSize.Width / 2), (float)aoRectangle.Bottom, (float)aoRectangle.Left + (float)(aoSize.Width / 2), (float)aoRectangle.Bottom);
            graphicsPath.AddArc(aoRectangle.Left, aoRectangle.Bottom - aoSize.Height, aoSize.Width, aoSize.Height, 90f, 90f);
            graphicsPath.AddLine((float)aoRectangle.Left, (float)aoRectangle.Bottom - (float)(aoSize.Height / 2), (float)aoRectangle.Left, (float)aoRectangle.Top + (float)(aoSize.Height / 2));
            graphicsPath.AddArc(aoRectangle.Left, aoRectangle.Top, aoSize.Width, aoSize.Height, 180f, 90f);
            return graphicsPath;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            this.moTextSize = e.Graphics.MeasureString(this.Text, this.Font);
            SmoothingMode smoothingMode = e.Graphics.SmoothingMode;
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            this.DrawBorder(e.Graphics, this.BorderRectangle);
            e.Graphics.FillPath(this.InteriorRegionPathBrush, this.InteriorRegionPath);
            this.DrawInterior(e.Graphics);
            StringFormat format = new StringFormat();
            RectangleF layoutRectangle = new RectangleF((float)this.BorderRectangle.X + (float)(this.mosizeBorderPixelIndent.Width / 2) + 8f, (float)(this.BorderRectangle.Y + 2), this.moTextSize.Width + (float)(this.mosizeBorderPixelIndent.Width / 2), this.moTextSize.Height);
            e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.moHeadingTextColor), layoutRectangle, format);
            e.Graphics.SmoothingMode = smoothingMode;
            base.Region = new Region(this.ExteriorRegionPath);
        }
    }
}
